//
//  HMNewsCollectionViewController.m
//  weiboOC
//
//  Created by 刘耀宗 on 16/4/11.
//  Copyright © 2016年 刘耀宗. All rights reserved.
//

#import "HMNewsCollectionViewController.h"
#import "HMFlowout.h"
#import "HMNewsCell.h"

@interface HMNewsCollectionViewController ()
@property (nonatomic, assign) BOOL isShow;
@end

@implementation HMNewsCollectionViewController

static NSString * const reuseIdentifier = @"Cell";
- (instancetype)init
{
    self = [super init];
    if (self) {
        HMFlowout *layout = [[HMFlowout alloc] init];
        
        UICollectionView *collection=[[UICollectionView alloc] initWithFrame:[UIScreen mainScreen].bounds collectionViewLayout:layout];
        
        self.collectionView=collection;
        [self.collectionView registerClass:[HMNewsCell class] forCellWithReuseIdentifier:reuseIdentifier];
         self.collectionView.backgroundColor=[UIColor whiteColor];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
   
    
  
    
    
}

//代理方法  滚动结束的时候
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
   
    NSInteger index=(NSInteger)scrollView.contentOffset.x/[UIScreen mainScreen].bounds.size.width;
    NSLog(@"index=%ld",index);
    if (index == 3) {
        NSIndexPath *path=[NSIndexPath indexPathForRow:index inSection:0];
        HMNewsCell *cell=[self.collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:path];
        
        self.isShow = YES;
    
        [self.collectionView reloadData];
    
    }


}




- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {

    return 4;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    HMNewsCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    cell.index=indexPath.item;

    
    NSLog(@"当前第%ld个的地址是%p按钮的地址是%p",indexPath.item,cell,cell.Newsbtn);
    
    if (self.isShow == YES) {
        [self showBTn:cell.Newsbtn];

    }
    
    return cell;
}

-(void)showBTn:(UIButton *)btn
{
    btn.hidden = NO;
    //将缩放比例改成0
    btn.transform= CGAffineTransformMakeRotation(0);
    //弹簧效果
    [UIView animateWithDuration:0.25 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:5 options:UIViewAnimationOptionLayoutSubviews animations:^{
        btn.transform= CGAffineTransformIdentity;
        [btn setBackgroundColor:[UIColor redColor]];
    } completion:^(BOOL finished) {
        NSLog(@"完成了");
        
    }];
    //注册单击事件
    [btn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    

}
-(void)click:(UIButton *)btn
{
    
    



}

@end
